<template>
    <div class="recommend">
        <div class="recommend-item" v-for="item in recommends.slice(0,4)" :key="item.id">
            <a href="" @click.prevent = "goD(item.id)">
                <img v-lazy="item.cover_url" alt="">
                <div>{{item.title}}</div>
            </a>
        </div>
    </div>
</template>

<script>
import { useRouter } from 'vue-router';
export default {
    // 组件父传子
    props:{
        recommends:{
            type: Array,
            default(){
                return []
            }
        }
    },
    setup(){
        // 在setup中使用
        const router = useRouter();
        
        // 跳转到详情页面
        const goD = (id) => {
            router.push({ path: '/detail',query:{ id } });
        }
        
        //外露的方法要返回
        return { goD }
    }
}
</script>

<style scoped lang="scss">
    .recommend {
        display: flex;
        width:100%;
        text-align: center;
        padding: 15px 0 30px;
        border-bottom:8px solid #EEE;
        font-size:12px;
    }
    .recommend-item {
        flex:1;
        img {
            width:70px;
            height:70px;
            margin-bottom: 10px;
        }
    }

</style>